package maskedpixel.ogmo.utils 
{
	/**
	 * ...
	 * @author Erin M Gunn
	 */
	public class OgmoFolder
	{
		/**
		 * The name of this folder.
		 */
		public var name:String;
		
		/**
		 * The image of this folder.
		 */
		public var image:String;
		
		/**
		 * The list of objects that this folder contains.
		 */
		public function get objectList():Vector.<OgmoObject> 
		{
			return _objectList;
		}
		
		/**
		 * Constructor.
		 * @param	name	Name of the folder.
		 * @param	image	The location and name of the image file to use.
		 */
		public function OgmoFolder(name:String, image:String) 
		{
			this.name = name;
			this.image = image;
		}
		
		/**
		 * Generate the XML representation of the Folder in the Ogmo project file.
		 * @return
		 */
		public function generateXML():XML
		{
			var xml:XML = new XML();
			xml = <folder/>;
			xml.@name = name;
			xml.@image = image;
			for each(var obj:OgmoObject in _objectList)
			{
				xml.*[xml.children().length()] = obj.generateXML();
			}
			
			return xml;
		}
		
		/**
		 * Register an OgmoObject with this folder.
		 * @param	...objects	Any of an OgmoObject, Vector.<OgmoObject> or
		 * 						an Array of OgmoObject's.
		 */
		public function registerObject(...objects):void
		{
			for each(var object:Object in objects)
			{
				if (object is OgmoObject)
				{
					if (_objectList.indexOf(object) == -1)
					{
						_objectList.push(object);
					}
				}
				if (object is Vector.<OgmoObject> || object is Array)
				{
					if (_objectList.indexOf(object) == -1)
					{
						_objectList.push(object);
					}
				}
				
			}
		}
		
		// Objects
		/** @private */ private var _objectList:Vector.<OgmoObject> = new Vector.<OgmoObject>();
	}

}